package comment

import (
	"dy/pkg/code"
	"dy/pkg/jwt"

	"github.com/gin-gonic/gin"
)

func (u *ControllerComment) CommentList(ctx *gin.Context) {
	type param struct {
		Token   string `form:"token" json:"token" binding:"required"`
		VideoId int    `form:"video_id" json:"video_id" binding:"required"`
	}

	var request param
	err := ctx.Bind(&request)
	if err != nil {
		code.ErrReturn(ctx, err.Error())
		return
	}
	_, err = jwt.ParseToken(request.Token)
	if err != nil {
		code.ErrReturn(ctx, err.Error())
		return
	}

	list, err := u.srv.Comment().List(ctx, request.VideoId)
	if err != nil {
		code.ErrReturn(ctx, err.Error())
		return
	}

	ctx.JSON(200, gin.H{
		"status_code":  0,
		"status_msg":   "success",
		"comment_list": list,
	})
}
